/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package main.gui;

import javax.swing.JOptionPane;
import main.beans.*;
import main.core.ControladorArquivo;
import main.exceptions.CPFInvalidoException;
import main.exceptions.EspecieIndefinidaException;
import main.exceptions.GravidadeInvalidaException;
import main.exceptions.NomeVazioException;
import main.interfaces.Cadastravel;

/**
 *
 * @author Icaro
 */
public class TelaCadastro extends javax.swing.JFrame {

    /**
     * Creates new form TelaCadastro
     */
    public TelaCadastro() {
        initComponents();
        setPanelsInvisible();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        painelOpcoes = new javax.swing.JPanel();
        botaoVoltar = new javax.swing.JButton();
        botaoCadastroDoenca = new javax.swing.JButton();
        botaoCadastroAdotante = new javax.swing.JButton();
        botaoCadastroAnimal = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        painelPrincipal = new javax.swing.JPanel();
        painelAdotante = new javax.swing.JPanel();
        jLabel3 = new javax.swing.JLabel();
        nomePessoaJTF = new javax.swing.JTextField();
        cpfJTF = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        telefoneJTF = new javax.swing.JTextField();
        emailJTF = new javax.swing.JTextField();
        jScrollPane1 = new javax.swing.JScrollPane();
        enderecoJTA = new javax.swing.JTextArea();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        painelAnimal = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        especieJTF = new javax.swing.JTextField();
        racaJTF = new javax.swing.JTextField();
        jLabel9 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        corJTF = new javax.swing.JTextField();
        nomeAnimalJTF = new javax.swing.JTextField();
        jLabel11 = new javax.swing.JLabel();
        jLabel12 = new javax.swing.JLabel();
        jLabel13 = new javax.swing.JLabel();
        sexoComboBox = new javax.swing.JComboBox();
        painelDoenca = new javax.swing.JPanel();
        jLabel14 = new javax.swing.JLabel();
        nomeDoencaJTF = new javax.swing.JTextField();
        jScrollPane2 = new javax.swing.JScrollPane();
        descricaoDoencaJTA = new javax.swing.JTextArea();
        jLabel15 = new javax.swing.JLabel();
        jLabel16 = new javax.swing.JLabel();
        jLabel17 = new javax.swing.JLabel();
        gravidadeComboBox = new javax.swing.JComboBox();
        painelVazio = new javax.swing.JPanel();
        painelCadastrar = new javax.swing.JPanel();
        botaoCadastrar = new javax.swing.JButton();
        botaoCancelar = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosed(java.awt.event.WindowEvent evt) {
                formWindowClosed(evt);
            }
        });

        botaoVoltar.setText("Voltar");
        botaoVoltar.setToolTipText("Voltar para tela principal");
        botaoVoltar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botaoVoltarActionPerformed(evt);
            }
        });

        botaoCadastroDoenca.setText("Doença");
        botaoCadastroDoenca.setToolTipText("Cadastra uma Doença");
        botaoCadastroDoenca.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botaoCadastroDoencaActionPerformed(evt);
            }
        });

        botaoCadastroAdotante.setText("Adotante");
        botaoCadastroAdotante.setToolTipText("Cadastra um Adotante");
        botaoCadastroAdotante.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botaoCadastroAdotanteActionPerformed(evt);
            }
        });

        botaoCadastroAnimal.setText("Animal");
        botaoCadastroAnimal.setToolTipText("Cadastra um Animal");
        botaoCadastroAnimal.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botaoCadastroAnimalActionPerformed(evt);
            }
        });

        jLabel1.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel1.setText("O que deseja cadastrar?");

        javax.swing.GroupLayout painelOpcoesLayout = new javax.swing.GroupLayout(painelOpcoes);
        painelOpcoes.setLayout(painelOpcoesLayout);
        painelOpcoesLayout.setHorizontalGroup(
            painelOpcoesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(painelOpcoesLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addGap(18, 18, 18)
                .addComponent(botaoCadastroAnimal, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(botaoCadastroAdotante, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(botaoCadastroDoenca, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(botaoVoltar, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        painelOpcoesLayout.setVerticalGroup(
            painelOpcoesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(painelOpcoesLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(painelOpcoesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(botaoCadastroAnimal)
                    .addComponent(botaoCadastroAdotante)
                    .addComponent(botaoCadastroDoenca)
                    .addComponent(botaoVoltar))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        painelPrincipal.setPreferredSize(new java.awt.Dimension(586, 177));
        painelPrincipal.setLayout(new java.awt.CardLayout());

        painelAdotante.setPreferredSize(new java.awt.Dimension(586, 177));

        jLabel3.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jLabel3.setText("Cadastro de Adotante");

        jLabel4.setText("Nome:");

        jLabel5.setText("CPF:");

        enderecoJTA.setColumns(20);
        enderecoJTA.setRows(5);
        jScrollPane1.setViewportView(enderecoJTA);

        jLabel6.setText("Endereço:");

        jLabel7.setText("Telefone:");

        jLabel8.setText("eMail:");

        javax.swing.GroupLayout painelAdotanteLayout = new javax.swing.GroupLayout(painelAdotante);
        painelAdotante.setLayout(painelAdotanteLayout);
        painelAdotanteLayout.setHorizontalGroup(
            painelAdotanteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(painelAdotanteLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(painelAdotanteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(painelAdotanteLayout.createSequentialGroup()
                        .addGroup(painelAdotanteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel6)
                            .addComponent(jLabel7))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(painelAdotanteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(painelAdotanteLayout.createSequentialGroup()
                                .addComponent(nomePessoaJTF, javax.swing.GroupLayout.DEFAULT_SIZE, 316, Short.MAX_VALUE)
                                .addGap(18, 18, 18)
                                .addComponent(jLabel5)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(cpfJTF, javax.swing.GroupLayout.PREFERRED_SIZE, 140, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(jScrollPane1)
                            .addGroup(painelAdotanteLayout.createSequentialGroup()
                                .addComponent(telefoneJTF, javax.swing.GroupLayout.PREFERRED_SIZE, 130, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(jLabel8)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(emailJTF))))
                    .addComponent(jLabel4)
                    .addComponent(jLabel3))
                .addContainerGap())
        );
        painelAdotanteLayout.setVerticalGroup(
            painelAdotanteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(painelAdotanteLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel3)
                .addGap(18, 18, 18)
                .addGroup(painelAdotanteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(nomePessoaJTF, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel4)
                    .addComponent(cpfJTF, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel5))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(painelAdotanteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel6)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(painelAdotanteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(telefoneJTF, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel7)
                    .addComponent(jLabel8)
                    .addComponent(emailJTF, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        painelPrincipal.add(painelAdotante, "card2");

        painelAnimal.setPreferredSize(new java.awt.Dimension(586, 101));

        jLabel2.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jLabel2.setText("Cadastro de Animal");

        jLabel9.setText("Espécie:");

        jLabel10.setText("Raça:");

        jLabel11.setText("Sexo:");

        jLabel12.setText("Cor:");

        jLabel13.setText("Nome:");

        sexoComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Masculino", "Feminino" }));

        javax.swing.GroupLayout painelAnimalLayout = new javax.swing.GroupLayout(painelAnimal);
        painelAnimal.setLayout(painelAnimalLayout);
        painelAnimalLayout.setHorizontalGroup(
            painelAnimalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(painelAnimalLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(painelAnimalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(painelAnimalLayout.createSequentialGroup()
                        .addComponent(jLabel2)
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(painelAnimalLayout.createSequentialGroup()
                        .addGroup(painelAnimalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(painelAnimalLayout.createSequentialGroup()
                                .addGroup(painelAnimalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel9)
                                    .addComponent(jLabel12, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGap(18, 18, 18)
                                .addGroup(painelAnimalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(especieJTF, javax.swing.GroupLayout.DEFAULT_SIZE, 170, Short.MAX_VALUE)
                                    .addComponent(corJTF))
                                .addGap(18, 18, 18)
                                .addGroup(painelAnimalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel10)
                                    .addComponent(jLabel13))
                                .addGap(18, 18, 18)
                                .addGroup(painelAnimalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(racaJTF, javax.swing.GroupLayout.DEFAULT_SIZE, 170, Short.MAX_VALUE)
                                    .addComponent(nomeAnimalJTF)))
                            .addGroup(painelAnimalLayout.createSequentialGroup()
                                .addComponent(jLabel11, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(sexoComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGap(0, 111, Short.MAX_VALUE))))
        );
        painelAnimalLayout.setVerticalGroup(
            painelAnimalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, painelAnimalLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel2)
                .addGap(18, 18, 18)
                .addGroup(painelAnimalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(especieJTF, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel9)
                    .addComponent(jLabel10)
                    .addComponent(racaJTF, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(painelAnimalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(corJTF, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel12)
                    .addComponent(jLabel13)
                    .addComponent(nomeAnimalJTF, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(painelAnimalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel11, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(sexoComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(59, 59, 59))
        );

        painelPrincipal.add(painelAnimal, "card3");

        jLabel14.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jLabel14.setText("Cadastro de Doença");

        descricaoDoencaJTA.setColumns(20);
        descricaoDoencaJTA.setRows(5);
        jScrollPane2.setViewportView(descricaoDoencaJTA);

        jLabel15.setText("Nome:");

        jLabel16.setText("Descrição:");

        jLabel17.setText("Gravidade:");

        gravidadeComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Leve", "Médio", "Grave" }));

        javax.swing.GroupLayout painelDoencaLayout = new javax.swing.GroupLayout(painelDoenca);
        painelDoenca.setLayout(painelDoencaLayout);
        painelDoencaLayout.setHorizontalGroup(
            painelDoencaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(painelDoencaLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(painelDoencaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(painelDoencaLayout.createSequentialGroup()
                        .addGroup(painelDoencaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel15)
                            .addComponent(jLabel16))
                        .addGap(7, 7, 7)
                        .addGroup(painelDoencaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(nomeDoencaJTF)
                            .addComponent(jScrollPane2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 509, Short.MAX_VALUE)))
                    .addGroup(painelDoencaLayout.createSequentialGroup()
                        .addGroup(painelDoencaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel14)
                            .addGroup(painelDoencaLayout.createSequentialGroup()
                                .addComponent(jLabel17)
                                .addGap(18, 18, 18)
                                .addComponent(gravidadeComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addContainerGap())
        );
        painelDoencaLayout.setVerticalGroup(
            painelDoencaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(painelDoencaLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel14)
                .addGap(18, 18, 18)
                .addGroup(painelDoencaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(nomeDoencaJTF, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel15))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(painelDoencaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(painelDoencaLayout.createSequentialGroup()
                        .addComponent(jLabel16)
                        .addGap(0, 56, Short.MAX_VALUE))
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(painelDoencaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel17)
                    .addComponent(gravidadeComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        painelPrincipal.add(painelDoenca, "card4");

        painelVazio.setPreferredSize(new java.awt.Dimension(586, 177));
        painelVazio.setLayout(null);
        painelPrincipal.add(painelVazio, "card5");

        botaoCadastrar.setText("Cadastrar");
        botaoCadastrar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botaoCadastrarActionPerformed(evt);
            }
        });

        botaoCancelar.setText("Cancelar");
        botaoCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botaoCancelarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout painelCadastrarLayout = new javax.swing.GroupLayout(painelCadastrar);
        painelCadastrar.setLayout(painelCadastrarLayout);
        painelCadastrarLayout.setHorizontalGroup(
            painelCadastrarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(painelCadastrarLayout.createSequentialGroup()
                .addContainerGap(188, Short.MAX_VALUE)
                .addComponent(botaoCadastrar, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(botaoCancelar, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(188, 188, 188))
        );
        painelCadastrarLayout.setVerticalGroup(
            painelCadastrarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, painelCadastrarLayout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(painelCadastrarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(botaoCadastrar)
                    .addComponent(botaoCancelar))
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(painelOpcoes, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(painelPrincipal, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(painelCadastrar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(painelOpcoes, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(painelPrincipal, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(painelCadastrar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void botaoVoltarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botaoVoltarActionPerformed
        this.dispose();
        TelaPrincipal.activateMainWindow();
    }//GEN-LAST:event_botaoVoltarActionPerformed

    private void formWindowClosed(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosed
        TelaPrincipal.activateMainWindow();
    }//GEN-LAST:event_formWindowClosed

    private void botaoCadastroAnimalActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botaoCadastroAnimalActionPerformed
        setPanelsInvisible();
        painelAnimal.setVisible(true);
    }//GEN-LAST:event_botaoCadastroAnimalActionPerformed

    private void botaoCadastroAdotanteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botaoCadastroAdotanteActionPerformed
        setPanelsInvisible();
        painelAdotante.setVisible(true);
    }//GEN-LAST:event_botaoCadastroAdotanteActionPerformed

    private void botaoCadastroDoencaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botaoCadastroDoencaActionPerformed
        setPanelsInvisible();
        painelDoenca.setVisible(true);
    }//GEN-LAST:event_botaoCadastroDoencaActionPerformed

    private void botaoCadastrarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botaoCadastrarActionPerformed
            Cadastravel cadastravel = null;
            if (painelAdotante.isVisible())
                cadastravel = geraAdotante();
            if (painelAnimal.isVisible())
                cadastravel = geraAnimal();
            if (painelDoenca.isVisible())
                cadastravel = geraDoenca();

            ControladorArquivo controlador = new ControladorArquivo();
            if (cadastravel != null) {
                controlador.save(cadastravel);
                setPanelsInvisible();
                JOptionPane.showMessageDialog(painelVazio, "Cadastro feito com sucesso!");
            }
    }//GEN-LAST:event_botaoCadastrarActionPerformed

    private void botaoCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botaoCancelarActionPerformed
        setPanelsInvisible();
    }//GEN-LAST:event_botaoCancelarActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(TelaCadastro.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(TelaCadastro.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(TelaCadastro.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(TelaCadastro.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new TelaCadastro().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton botaoCadastrar;
    private javax.swing.JButton botaoCadastroAdotante;
    private javax.swing.JButton botaoCadastroAnimal;
    private javax.swing.JButton botaoCadastroDoenca;
    private javax.swing.JButton botaoCancelar;
    private javax.swing.JButton botaoVoltar;
    private javax.swing.JTextField corJTF;
    private javax.swing.JTextField cpfJTF;
    private javax.swing.JTextArea descricaoDoencaJTA;
    private javax.swing.JTextField emailJTF;
    private javax.swing.JTextArea enderecoJTA;
    private javax.swing.JTextField especieJTF;
    private javax.swing.JComboBox gravidadeComboBox;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTextField nomeAnimalJTF;
    private javax.swing.JTextField nomeDoencaJTF;
    private javax.swing.JTextField nomePessoaJTF;
    private javax.swing.JPanel painelAdotante;
    private javax.swing.JPanel painelAnimal;
    private javax.swing.JPanel painelCadastrar;
    private javax.swing.JPanel painelDoenca;
    private javax.swing.JPanel painelOpcoes;
    private javax.swing.JPanel painelPrincipal;
    private javax.swing.JPanel painelVazio;
    private javax.swing.JTextField racaJTF;
    private javax.swing.JComboBox sexoComboBox;
    private javax.swing.JTextField telefoneJTF;
    // End of variables declaration//GEN-END:variables

    private void setPanelsInvisible() {
        painelAdotante.setVisible(false);
        painelAnimal.setVisible(false);
        painelDoenca.setVisible(false);
        painelVazio.setVisible(true);
    }

    private Adotante geraAdotante() {
        String nome = nomePessoaJTF.getText();
        String cpf = cpfJTF.getText();
        String endereco = enderecoJTA.getText();
        String telefone = telefoneJTF.getText();
        String email = emailJTF.getText();

        Adotante adotante = null;
        try {
            adotante = new Adotante(nome, cpf);
            adotante.setEndereco(endereco);
            adotante.setTelefone(telefone);
            adotante.setEmail(email);
        } catch (Exception ex) {
            if (ex instanceof NomeVazioException)
                JOptionPane.showMessageDialog(painelAdotante, "Nome inválido.");
            if (ex instanceof CPFInvalidoException)
                JOptionPane.showMessageDialog(painelAdotante, "CPF inválido.");
        }
        return adotante;
    }

    private Animal geraAnimal() {
        String especie = especieJTF.getText();
        String raca = racaJTF.getText();
        String cor = corJTF.getText();
        String nome = nomeAnimalJTF.getText();
        int sexo = sexoComboBox.getSelectedIndex();

        Animal animal = null;
        try {
        animal = new Animal(nome, especie, raca, sexo, cor);
        } catch (Exception ex) {
            if (ex instanceof NomeVazioException)
                JOptionPane.showMessageDialog(painelAnimal, "Nome inválido.");
            if (ex instanceof EspecieIndefinidaException)
                JOptionPane.showMessageDialog(painelAnimal, "Espécie não especificada.");
        }
        return animal;
    }

    private Doenca geraDoenca() {
        String nome = nomeDoencaJTF.getText();
        String descricao = descricaoDoencaJTA.getText();
        int gravidade = gravidadeComboBox.getSelectedIndex()+1;

        Doenca doenca = null;
        try {
            doenca = new Doenca(nome, gravidade);
            doenca.setDescricao(descricao);
        } catch (Exception ex) {
            if (ex instanceof NomeVazioException)
                JOptionPane.showMessageDialog(painelDoenca, "Nome inválido.");
            if (ex instanceof GravidadeInvalidaException)
                JOptionPane.showMessageDialog(painelDoenca, "Grau de gravidade inválido.");
        }
        return doenca;
    }
}
